home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / wctunits.zip / MOUSE.PAS < prev    next >
Pascal/Delphi Source File  |  1991-08-03  |  26KB  |  821 lines

  1. UNIT Mouse;
  2. { Mouse unit for Turbo Pascal.
  3.   The comments in this unit were basically copied directly
  4.   from the Advanced MS Dos Programing book, the section on
  5.   the Microsoft Mouse Driver, which was the source of all
  6.   the mouse interrupt functions and their parameters.
  7. }
  8.  
  9.  
  10. INTERFACE
  11.  
  12. USES
  13.   Dos;
  14.  
  15. CONST
  16.   LeftButton = 1;
  17.   RightButton = 2;
  18.   CenterButton = 4;
  19.   AnyButton = 7;
  20.  
  21. var
  22.   mouseon: boolean;
  23.  
  24. PROCEDURE InitMouse(VAR Buttons : word; VAR Err : boolean);
  25. { Initializes the mouse driver.
  26.   Call:    nothing
  27.   Returns: Buttons = number of mouse buttons
  28.        Err     = false if mouse support is available, true otherwise
  29.   Note:    * After a call to this function the driver is initialized to the
  30.     following state:
  31.     - Mouse pointer at screen center and hidden.
  32.     - Display page is set to zero.
  33.     - Mouse pointer shape set to default arrow shape in graphics modes,
  34.     or reverse block in text modes.
  35.     - User mouse event handlers are disabled.
  36.     - Light pen emulation enabled.
  37.     - Mouse sensitivity set to default vales (see SetMouseSense)
  38.     - Pointer limits set to entire screen.
  39.   - Set mouseon to false
  40. }
  41.  
  42. PROCEDURE Showmouse;
  43. { Displays the mouse pointer, and cancels any pointer exclusion area. }
  44.  
  45. PROCEDURE Hidemouse;
  46. { Removes the mouse pointer from the screen, but continues to track the
  47.   position of the mouse. }
  48.  
  49. FUNCTION ButtonPressed(Mask : word) : boolean;
  50. { Returns a true value if the specified button(s) is pressed.
  51.   Call:    Mask = bit mask of desired button(s)
  52.     bit(s)  Significance(if set)
  53.     0       left button
  54.     1       right button
  55.     2       center button
  56.     3-15    reserved(0)
  57.   : True is button is pressed, false otherwise.
  58.   Note:    * The constants LeftButton, RightButton, CenterButton, and
  59.     AnyButton can be used for the bit masking.  They equal 1, 2,
  60.     4, and 7 respectivly.
  61. }
  62.  
  63. PROCEDURE GetMousePosition(VAR Buttons, Horiz, Vert : word);
  64. { Returns the current mouse button status and pointer position.
  65.   Call:    nothing
  66.   Returns: Buttons = mouse button status
  67.     Horiz   = horizontal (X) coordinate
  68.     Vert    = vertical (Y) coordinate
  69.   Note:    * Coordinates are in pixels regardless of the current display mode.
  70.     Position (0,0) is the upper left corner of the screen.
  71. }
  72.  
  73. FUNCTION MouseIn(x1,y1,x2,y2: word):boolean;
  74. { Returns true if mouse is within rectangle with upper-left
  75.   corner (x1,y1) and lower-right corner (x2,y2).
  76. }
  77.  
  78. PROCEDURE SetPointerPosition(Horiz, Vert : word);
  79. { Set the position of the pointer.  The pointer is displayed in the new
  80.   position unless it has been hidden using HidePointer or it is an exclusion
  81.   area defined by SetPointerExcl.
  82.   Call:    Horiz = horizontal (X) coordinate
  83.     Vert  = vertical (Y) coordinate
  84.   Returns: nothing
  85.   Notes:   * Coordinates are in pixels regardless of the current display mode.
  86.     Position (0,0) is the upper left corner of the screen.
  87.     * The position is adjusted if necessary to lie within the pointer
  88.     limits set by SetLimits.
  89. }
  90. PROCEDURE GetPressInfo(Button : word;
  91.                VAR Stat, Count, Horiz, Vert : word);
  92. { Returns the current status of all mouse buttons, and the number of presses
  93.   and position of the last press for a specifed mouse button since the last
  94.   call to this procedure for that button.  The press counter for the button
  95.   is reset to zero.
  96.   Call:    Button = button identifier
  97.     0 = left button
  98.     1 = right button
  99.     2 = center button
  100.   : Stat   = button status
  101.     bit(s)  Significance(if set)
  102.     0       left button is down
  103.     1       right button is down
  104.     2       center button is down
  105.     3-15    reserved(0)
  106.     Count  = button press counter
  107.     Horiz  = horizontal (X) coordinate of last button press
  108.     Vert   = vertical (Y) coordinate of last button press
  109. }
  110. PROCEDURE GetReleaseInfo(Button : word;
  111.              VAR Stat, Count, Horiz, Vert : word);
  112. { Returns the current status of all mouse buttons, and the number of releases
  113.   and position of the last release for a specifed mouse button since the last
  114.   call to this procedure for that button.  The release counter for the button
  115.   is reset to zero.
  116.   Call:    Button = button identifier
  117.     0 = left button
  118.     1 = right button
  119.     2 = center button
  120.   Returns: Stat   = button status
  121.     bit(s)  Significance(if set)
  122.     0       left button is down
  123.     1       right button is down
  124.     2       center button is down
  125.     3-15    reserved(0)
  126.     Count  = button release counter
  127.     Horiz  = horizontal (X) coordinate of last button release
  128.     Vert   = vertical (Y) coordinate of last button release
  129. }
  130. PROCEDURE SetLimits(HorMin, HorMax, VerMin, VerMax : word);
  131. { Limits the mouse pointer to stay within a certian area.
  132.   Call:    HorMin = Minimum horizontal (X) coordinate
  133.     HorMax = Maximum horizontal (X) coordinate
  134.     VerMin = Minimum vertical (Y) coordinate
  135.     VerMax = Maximum vertical (Y) coordinate
  136.   Returns: nothing
  137.   Note:    * If both HorMin and HorMax are zero then then the previous
  138.     horizontal limits remain unchanged; the same is true for
  139.     VerMin and VerMax.
  140. }
  141. PROCEDURE SetPointerShape(Horiz, Vert : word; Buffer : pointer);
  142. { Defines the shape, color, and hot spot of the pointer in graphics modes.
  143.   Call:    Horiz  = hot spot offset from the left
  144.     Vert   = hot spot offset from the top
  145.     Buffer = pointer to mouse pointer image buffer
  146.   Returns: nothing
  147.   Note:    * The pointer image buffer is 64 bytes long.  The first 32 bytes
  148.     contain a bit mask which is ANDed with the screen image, and the
  149.     remaining 32 bytes are then XORed with the screen image.
  150.        * The hot spot is relative to the upper left corner of the pointer
  151.          image, and each offset must be in the range -16 to 16.  In display
  152.          modes 4 and 5, the horizontal offset must be an even number.
  153. }
  154. PROCEDURE SetTextPointer(PtrTyp, AND_Str, XOR_End : word);
  155. { Defines the shape and attributes of the mouse pointer in text modes.
  156.   Call:    PtrTyp  = pointer type
  157.              0 = software cursor
  158.              1 = hardware cursor
  159.        AND_Str = AND mask value (if PtrTyp = 0) or starting line for
  160.              cursor (if PtrTyp = 1)
  161.        XOR_End = XOR mask value (if PtrTyp = 0) or ending line for
  162.              cursor (if PtrTyp = 1)
  163.   Returns: nothing
  164.   Notes:   * If the software text cursor is selected, the masks in AND_Str and
  165.          XOR_End are mapped as follows:
  166.          Bit(s)   Significance
  167.          0-7      character code
  168.          8-10     foreground color
  169.          11       intensity
  170.          12-14    background color
  171.          15       blink
  172.          For Example, the following call would yeild a software cursor
  173.          that inverts the foreground and background colors:
  174.          SetTextPointer(0, $77FF, $7700);
  175.        * When the hardware text cursor is selected, the values in AND_Str
  176.          and XOR_End are the starting and ending lines for the blinking
  177.          cursor generated by the video adapter.  The maximum scan line
  178.          depends on the type of adapter and the current display mode.
  179. }
  180. PROCEDURE GetMotionCount(VAR Horiz, Vert : word);
  181. { Returns the net mouse displacement since the last call to this procedure.
  182.   The returned value is in mickeys; a positive number indicates travel to the
  183.   right or downwards, a negative number indicates travel to the left or
  184.   upwards.  One mickey represents approximately 1/200 of an inch of mouse
  185.   movement.
  186.   Call:    nothing
  187.   Returns: Horiz = horizontal (X) mickey count
  188.        Vert  = vertical (Y) mickey count
  189. }
  190. PROCEDURE SetEventHandler(EventMask : word; Handler : pointer);
  191. { Sets the address and event mask for an application program's mouse event
  192.   handler.  The handler is called by the mouse drvier whenever the specifed
  193.   mouse events occur.
  194.   Call:    EventMask = event mask
  195.                Bit(s)  Significance(if set)
  196.                0       mouse movement
  197.                1       left button pressed
  198.                2       left button released
  199.                3       right button pressed
  200.                4       right button released
  201.                5       center button pressed
  202.                6       center button released
  203.                7-15    reserved(0)
  204.        Handler   = Pointer to the handler procedure
  205.   Returns: nothing
  206.   Notes:   * The user-defined handler is entered from the mouse driver by a
  207.          far call with the registers